﻿using GRPCClass;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace SdtpsLibrary
{
    /// <summary>
    /// 控制节点的后台线程处理
    /// 检查任务队列，分配任务
    /// </summary>
    public class CenterWorker
    {
        System.Threading.Thread mythd;
        public void Start()
        {
            mythd = new System.Threading.Thread(new System.Threading.ThreadStart(Execute));
            mythd.Start();
        }
        public bool isStop
        {
            get;
            set;
        }
        public int errsleeptime = 5000;
        public int dosleeptime = 5000;

        /// <summary>
        ///  同步执行
        /// </summary>
        public void Execute()
        {
            do
            {
                while (TaskHanle.TaskNoAllotList.Count > 0)
                {
                    if (!TaskHanle.allotTask((TaskRequest)TaskHanle.TaskNoAllotList[0]))
                    {
                        System.Threading.Thread.Sleep(errsleeptime);
                    }
                }
                System.Threading.Thread.Sleep(dosleeptime);
            }
            while (!isStop);
        }
    }
}
